﻿//2010-03-25    新增維修記錄相關API       by Victor
//2010-04-13    新增派工記錄查詢API       by Victor
//2010-04-14    新增躉購費率設定API       by May
//2010-05-13    新增派工設備對應API       by Victor
//2010-05-13    修改查詢派工記錄API       by Victor
//2010-05-26    修改案場資料設定API       by Victor
//2010-06-01    修改案場資料設定API       by Victor
//2010-06-04    新增躉購費率設定API       by May
//2010-06-07    新增查詢Web_KeyDefinitionConfig  by May
//2010-06-07    新增案場簡訊設定API       by Victor
//2010-06-17    修改案場資料設定API       by Victor
//2010-06-21    修改案場資料設定API（新增案場IP與認證密碼） By Victor
//2010-06-30    新增系統日誌查詢API-2     by Victor
//2010-08-12    修改系統日誌查詢顯示平台案場名稱    By Victor
//2010-08-26    新增案場地址欄位            By Victor
//2010-09-06    新增QueryGroupConfig_cfg，傳入GrpNo查詢GroupConfig_cfg資料 By May
//2010-09-09    新增案場補助類型 02：永續校園方案  By Victor
//2010-10-21    新增查詢案場公告查詢API(傳入siteID, 查詢時間)    By May
//2010-10-22    新增查詢案場公告查詢API(傳入siteID的DataTable)   By May
//2010-12-08    update by May
//1.修正QuerySysLog，不查sitename出來
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.chttl.ienc.bean;
using java.util;
//Using Namespace
using System.Data;
using System.Data.SqlClient;

namespace DataAccess
{
    public class AccessSite
    {
        string strSQL;

        //案場管理          相關Table：Web_Site
        #region public bool AddWebSite     //新增案場資料
        /// <summary>
        /// 新增案場資料，回傳新增成功與否
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="SiteName">案場名稱</param>
        /// <param name="SolarType">太陽能系統型式</param>
        /// <param name="MeterType">電錶型式</param>
        /// <param name="ActualCapacity">實際容量</param>
        /// <param name="StatusFlag">專案狀態</param>
        /// <param name="OSSFlag">是否與OSS介接</param>
        /// <param name="BSCFlag">是否計算節能績效</param>
        /// <param name="City">所屬縣市</param>
        /// <param name="ApplyName">申請機構或姓名</param>
        /// <param name="ContractNo">合約編號</param>
        /// <param name="ContractDate">合約起始日期</param>
        /// <param name="ContractAmount">合約金額</param>
        /// <param name="ContactName">聯絡人</param>
        /// <param name="ContactTel">聯絡電話</param>
        /// <param name="BuildDate">完工日期</param>
        /// <param name="PMName">專案經理姓名</param>
        /// <param name="PMMobile">專案經理手機</param>
        /// <param name="AllowanceType">補助類型</param>
        /// <param name="Address">地址</param>
        /// <param name="Note">附註</param>
        /// <param name="ServerIP">案場IP</param>
        /// <param name="AuthPW">Web Service認證密碼</param>        
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>回傳新增成功與否</returns>
        public bool AddWebSite(string SiteID, string SiteName, string SolarType, string MeterType, string ActualCapacity, string StatusFlag, string OSSFlag, string BSCFlag, string City, string ApplyName, string ContractNo, DateTime ContractDate, string ContractAmount, string ContactName, string ContactTel, DateTime BuildDate, string PMName, string PMMobile, string AllowanceType, string Address, string Note, string ServerIP, string AuthPW, string ModifyUserID)
        {
            try
            {
                string strContractDate = ContractDate.ToString("yyyy/MM/dd HH:mm:ss");
                string strBuildDate = BuildDate.ToString("yyyy/MM/dd HH:mm:ss");

                strSQL = " Insert Into Web_Site(SiteID, SiteName, SolarType, MeterType, ActualCapacity, StatusFlag, OSSFlag, BSCFlag, City, ApplyName, ContractNo, ContractDate, ContractAmount, ContactName, ContactTel, BuildDate, PMName, PMMobile, AllowanceType, Address, Note, ServerIP, AuthPW, ModifyUserID) ";
                strSQL += "  Values('" + SiteID + "','" + SiteName + "','" + SolarType + "','" + MeterType + "','" + ActualCapacity + "','" + StatusFlag + "','" + OSSFlag + "','" + BSCFlag + "','" + City + "','" + ApplyName + "','" + ContractNo + "','" + strContractDate + "','" + ContractAmount + "','" + ContactName + "','" + ContactTel + "','" + strBuildDate + "','" + PMName + "','" + PMMobile + "','" + AllowanceType + "','" + Address + "','" + Note + "','" + ServerIP + "','" + AuthPW + "','" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddWebSite", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool UpdateWebSite     //修改案場資料
        /// <summary>
        /// 修改案場資料，回傳修改成功與否
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="SiteName">案場名稱</param>
        /// <param name="SolarType">太陽能系統型式</param>
        /// <param name="MeterType">電錶型式</param>
        /// <param name="ActualCapacity">實際容量</param>
        /// <param name="StatusFlag">專案狀態</param>
        /// <param name="OSSFlag">是否與OSS介接</param>
        /// <param name="BSCFlag">是否計算節能績效</param>
        /// <param name="City">所屬縣市</param>
        /// <param name="ApplyName">申請機構或姓名</param>
        /// <param name="ContractNo">合約編號</param>
        /// <param name="ContractDate">合約起始日期</param>
        /// <param name="ContractAmount">合約金額</param>
        /// <param name="ContactName">聯絡人</param>
        /// <param name="ContactTel">聯絡電話</param>
        /// <param name="BuildDate">完工日期</param>
        /// <param name="PMName">專案經理姓名</param>
        /// <param name="PMMobile">專案經理手機</param>
        /// <param name="AllowanceType">補助類型</param>
        /// <param name="Address">地址</param>
        /// <param name="Note">附註</param>
        /// <param name="ServerIP">案場IP</param>
        /// <param name="AuthPW">Web Service認證密碼</param>                
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>回傳修改成功與否</returns>
        public bool UpdateWebSite(string SiteID, string SiteName, string SolarType, string MeterType, string ActualCapacity, string StatusFlag, string OSSFlag, string BSCFlag, string City, string ApplyName, string ContractNo, DateTime ContractDate, string ContractAmount, string ContactName, string ContactTel, DateTime BuildDate, string PMName, string PMMobile, string AllowanceType, string Address, string Note, string ServerIP, string AuthPW, string ModifyUserID)
        {
            try
            {
                string strContractDate = ContractDate.ToString("yyyy/MM/dd HH:mm:ss");
                string strBuildDate = BuildDate.ToString("yyyy/MM/dd HH:mm:ss");

                strSQL = " Update Web_Site Set SiteName ='" + SiteName + "', SolarType='" + SolarType + "', MeterType='" + MeterType + "', ActualCapacity='" + ActualCapacity + "', StatusFlag='" + StatusFlag + "', OSSFlag='" + OSSFlag + "', BSCFlag='" + BSCFlag + "', City='" + City + "', ApplyName='" + ApplyName + "', ContractNo='" + ContractNo + "', ContractDate='" + strContractDate + "', ContractAmount='" + ContractAmount + "', ContactName='" + ContactName + "', ContactTel='" + ContactTel + "', BuildDate='" + strBuildDate + "', PMName='" + PMName + "', PMMobile='" + PMMobile + "', AllowanceType ='" + AllowanceType + "', Address='" + Address + "', Note='" + Note + "', ServerIP='" + ServerIP + "', AuthPW='" + AuthPW +"', ModifyUserID ='" + ModifyUserID + "', UpdateTime= GetDate() ";
                strSQL += " Where SiteID = '" + SiteID + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateWebSite", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelWebSite     //刪除案場資料
        /// <summary>
        /// 刪除案場資料，回傳刪除成功與否
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <returns>回傳刪除成功與否</returns>
        public bool DelWebSite(string SiteID)
        {
            try
            {
                strSQL = "Delete From Web_Site Where SiteID ='" + SiteID + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelWebSite", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QuerySite()        //查詢案場資料
        /// <summary>
        /// 查詢案場資料
        /// </summary>
        /// <returns>回傳案場資料</returns>
        public DataTable QuerySite()
        {
            try
            {
                strSQL = "Select Case StatusFlag When '1' Then '納管中' else '不納管' End as StatusFlagName,  Case SolarType When '1' Then '併聯型' When '2' Then '獨立型' When '3' Then '防災型' When '4' Then '混合型' Else '未知' End as SolarTypeName, ";
                strSQL += " Case MeterType When '1' Then '機械式電錶' When '2' Then '數位式電錶' End as MeterTypeName, Case OSSFlag When '1' Then '是' When '0' Then '否' End as OSSFlagName, Case BSCFlag When '1' Then '是' When '0' Then '否' End as BSCFlagName, ";
                strSQL += " Case AllowanceType When '00' Then '無' When '01' Then '經濟部能源局' When '02' Then '永續校園方案' End as ShowAllowanceType, ";
                strSQL += " * From Web_Site";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySite", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //系統日誌          相關Table：Web_SysLog
        #region public DataTable QuerySysLog(string EventType)       //查詢系統日誌
        public DataTable QuerySysLog(string EventType)
        {
            try
            {
                strSQL = "Select * From Web_SysLog";
                strSQL += " Where EventType='" + EventType + "' Order by Web_SysLog.UpdateTime Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySysLog-1", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QuerySysLog(string EventType, string SiteID)       //查詢系統日誌
        public DataTable QuerySysLog(string EventType, string SiteID)
        {
            try
            {
                strSQL = "Select * From Web_SysLog";
                strSQL += " Where Web_SysLog.SiteID ='" + SiteID + "' and EventType='" + EventType + "' Order by Web_SysLog.UpdateTime Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySysLog-2", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //公告設定          相關Table：Web_Announcement
        #region public bool AddAnnouncement     //新增設備維修記錄
        public bool AddAnnouncement(string SiteID, string Title, string LV, string ApplyDate, string StartDate, string EndDate, string Note,string ModifyUserID)
        {
            try
            {
                strSQL = " Insert Into Web_Announcement(SiteID, Title, LV, ApplyDate, StartDate, EndDate, Note, ModifyUserID) ";
                strSQL += " Values('" + SiteID + "','" + Title + "','" + LV + "','" + ApplyDate + "','" + StartDate + "','" + EndDate + "','" + Note + "','" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddAnnouncement", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool UpdateAnnouncement     //修改設備維修記錄
        public bool UpdateAnnouncement(string AnnounceSN, string SiteID, string Title, string LV, string ApplyDate, string StartDate, string EndDate, string Note, string ModifyUserID)
        {
            try
            {
                strSQL = " Update Web_Announcement Set SiteID ='" + SiteID + "', Title='" + Title + "', LV='" + LV + "', ApplyDate='" + ApplyDate + "', StartDate='" + StartDate + "', EndDate='" + EndDate + "', Note='" + Note + "', ModifyUserID ='" + ModifyUserID + "', UpdateTime= GetDate() ";
                strSQL += " Where AnnounceSN = '" + AnnounceSN + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateSiteMaintain", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelAnnouncement     //刪除設備維修記錄
        public bool DelAnnouncement(string AnnounceSN)
        {
            try
            {
                strSQL = "Delete From Web_Announcement Where AnnounceSN ='" + AnnounceSN + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelAnnouncement", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QueryAnnouncement     //查詢設備維修記錄
        public DataTable QueryAnnouncement()
        {
            try
            {
                strSQL = "Select *, Case LV When '1' Then '重要' When '0' Then '一般' End as LVName From Web_Announcement Order by LV Desc, AnnounceSN Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryAnnouncement", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //維修記錄相關      相關Table：Web_SiteMaintain、Web_SiteErrType（需補充XML說明）
        #region  public DataTable QuerySiteErrType()        //查詢故障設備種類
        public DataTable QuerySiteErrType()
        {
            try
            {
                strSQL = " Select * From Web_SiteErrType ";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteErrType", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public bool AddSiteMaintain     //新增設備維修記錄
        public bool AddSiteMaintain(string SiteID, string ErrTypeID, string InfoUserID, DateTime InfoDate, string InfoMsg, string FixUserName, string FixUserPhone, DateTime? FixDate, string FixMsg, string FixStatus, string Note, string ModifyUserID)
        {
            try
            {
                string strInfoDate = InfoDate.ToString("yyyy/MM/dd HH:mm:ss");
                string strFixDate;
                strSQL = " Insert Into Web_SiteMaintain(SiteID, ErrTypeID, InfoUserID, InfoDate, InfoMsg, FixUserName, FixUserPhone, FixDate, FixMsg, FixStatus, Note, ModifyUserID) ";

                if(FixDate .HasValue )
                {
                    strFixDate = FixDate.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    strSQL += "  Values('" + SiteID + "','" + ErrTypeID + "','" + InfoUserID + "','" + strInfoDate + "','" + InfoMsg + "','" + FixUserName + "','" + FixUserPhone + "','" + strFixDate + "','" + FixMsg + "','" + FixStatus + "','" + Note + "','" + ModifyUserID + "')";
                }
                else
                {
                    strSQL += "  Values('" + SiteID + "','" + ErrTypeID + "','" + InfoUserID + "','" + strInfoDate + "','" + InfoMsg + "','" + FixUserName + "','" + FixUserPhone + "', null, '" + FixMsg + "','" + FixStatus + "','" + Note + "','" + ModifyUserID + "')";
                }

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddSiteMaintain", ex.ToString(), strSQL);
                return false ;
            }        
        }
        #endregion

        #region public bool UpdateSiteMaintain     //修改設備維修記錄
        public bool UpdateSiteMaintain(string MaintainSN, string SiteID, string ErrTypeID, string InfoUserID, DateTime InfoDate, string InfoMsg, string FixUserName, string FixUserPhone, DateTime? FixDate, string FixMsg, string FixStatus, string Note, string ModifyUserID)
        {
            try
            {
                string strInfoDate = InfoDate.ToString("yyyy/MM/dd HH:mm:ss");
                string strFixDate;                

                if (FixDate.HasValue)
                {
                    strFixDate = FixDate.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    strSQL = " Update Web_SiteMaintain Set SiteID ='" + SiteID + "', ErrTypeID='" + ErrTypeID + "', InfoUserID='" + InfoUserID + "', InfoDate='" + strInfoDate + "', InfoMsg='" + InfoMsg + "', FixUserName='" + FixUserName + "', FixUserPhone='" + FixUserPhone + "', FixDate='" + strFixDate + "', FixMsg='" + FixMsg + "', FixStatus='" + FixStatus + "', Note='" + Note + "', ModifyUserID ='" + ModifyUserID + "', UpdateTime= GetDate() ";
                    strSQL += " Where MaintainSN = '" + MaintainSN + "'";
                }
                else
                {
                    strSQL = " Update Web_SiteMaintain Set SiteID ='" + SiteID + "', ErrTypeID='" + ErrTypeID + "', InfoUserID='" + InfoUserID + "', InfoDate='" + strInfoDate + "', InfoMsg='" + InfoMsg + "', FixUserName='" + FixUserName + "', FixUserPhone='" + FixUserPhone + "', FixDate = null , FixMsg='" + FixMsg + "', FixStatus='" + FixStatus + "', Note='" + Note + "', ModifyUserID ='" + ModifyUserID + "', UpdateTime = GetDate() ";
                    strSQL += " Where MaintainSN = '" + MaintainSN + "'";
                }

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateSiteMaintain", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelSiteMaintain     //刪除設備維修記錄
        public bool DelSiteMaintain(string MaintainSN)
        {
            try
            {
                strSQL = "Delete From Web_SiteMaintain Where MaintainSN ='" + MaintainSN + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelSiteMaintain", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QuerySiteMaintain     //查詢設備維修記錄
        public DataTable QuerySiteMaintain()
        {
            try
            {
                strSQL = "Select Convert(varchar(10), InfoDate, 111) as InfoDate, Convert(varchar(10), FixDate, 111) as FixDate, * From Web_SiteMaintain Join Web_SiteErrType On Web_SiteMaintain.ErrTypeID = Web_SiteErrType.ErrTypeID Join Web_Site On Web_SiteMaintain.SiteID = Web_Site.SiteID Order by Web_SiteMaintain.UpdateTime Desc";

                return new CommonFun().GenDataTable (strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteMaintain-1", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QuerySiteMaintain     //查詢設備維修記錄
        public DataTable QuerySiteMaintain(string UserID)
        {
            try
            {
                strSQL = "Select Convert(varchar(10), InfoDate, 111) as InfoDate, Convert(varchar(10), FixDate, 111) as FixDate, * From Web_SiteMaintain Join Web_SiteErrType On Web_SiteMaintain.ErrTypeID = Web_SiteErrType.ErrTypeID Join Web_Site On Web_SiteMaintain.SiteID = Web_Site.SiteID Join Web_UserRight On Web_SiteMaintain.SiteID = Web_UserRight.SiteID ";
                strSQL += " Where Web_UserRight.UserID = '" + UserID + "' and Role ='1' Order by Web_SiteMaintain.UpdateTime Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteMaintain-2", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QuerySiteMaintain     //查詢設備維修記錄
        public DataTable QuerySiteMaintain(string UserID, string SiteID)
        {
            try
            {
                strSQL = "Select Convert(varchar(10), InfoDate, 111) as InfoDate, Convert(varchar(10), FixDate, 111) as FixDate, * From Web_SiteMaintain Join Web_SiteErrType On Web_SiteMaintain.ErrTypeID = Web_SiteErrType.ErrTypeID Join Web_Site On Web_SiteMaintain.SiteID = Web_Site.SiteID Join Web_UserRight On Web_SiteMaintain.SiteID = Web_UserRight.SiteID ";
                strSQL += " Where Web_UserRight.UserID = '" + UserID + "' and Web_SiteMaintain.SiteID ='" + SiteID + "' and Role ='1' Order by Web_SiteMaintain.UpdateTime Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteMaintain-3", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //派工記錄          相關Table：Web_OSSLog
        #region public DataTable QueryWebOSSLog     //查詢派工記錄
        public DataTable QueryWebOSSLog()
        {
            try
            {
                strSQL = "Select Case Web_OSSLog.AlarmType When '0' Then '無' When '1' Then '主要告警' When '2' Then '次要告警' Else '未知' End as AlarmTypeName, Case Web_OSSLog.Status When '0' Then '尚未派工' When '1' Then '已派工' End as ShowStatusName, Web_OSSLog.*, Web_Site.SiteName, TagConfig_cfg.TagName From Web_OSSLog ";
                strSQL += " Left Join Web_Site On Web_OSSLog.SiteID = Web_Site.SiteID ";
                strSQL += " Join TagConfig_cfg on Web_OSSLog.GrpNo = TagConfig_cfg.GrpNo and Web_OSSLog.ObjNo = TagConfig_cfg.ObjNo";
                strSQL += " Order by Web_OSSLog.UpdateTime Desc";

                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWebOSSLog", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //節費設定          相關Table：Web_SiteTariff
        #region public bool AddWeb_SiteTariff     //新增案場節費費率
        public bool AddWeb_SiteTariff(string SiteID, DateTime StartDate, float Tariff, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");

                strSQL = " Insert Into Web_SiteTariff(SiteID, StartDate, Tariff, ModifyUserID) ";

                strSQL += "  Values('" + SiteID + "','" + strStartDate + "'," + Tariff + ",'" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddWeb_SiteTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool　UpdateWeb_SiteTariff    //更新案場節費費率
        public bool UpdateWeb_SiteTariff(string SiteID, DateTime StartDate, float Tariff, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                strSQL = " Update Web_SiteTariff Set Tariff =" + Tariff + ", ModifyUserID='" + ModifyUserID + "', UpdateTime= GetDate() Where SiteID ='" + SiteID + "' and StartDate='" + strStartDate + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateWeb_SiteTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool　DeleteWeb_SiteTariff    //刪除案場節費費率
        public bool DeleteWeb_SiteTariff(string SiteID, DateTime StartDate)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                strSQL = " Delete From Web_SiteTariff Where SiteID = '" + SiteID + "' and StartDate = '" + strStartDate + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DeleteWeb_SiteTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QueryWeb_SiteTariff    //查詢案場節費費率
        public DataTable QueryWeb_SiteTariff()
        {
            try
            {
                strSQL = "Select * From Web_SiteTariff";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_SiteTariff", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryWeb_SiteTariff    //查詢案場節費費率
        public DataTable QueryWeb_SiteTariff(DataTable dtSiteID)
        {
            try
            {
                string strSiteID = "";
                for (int i = 0; i < dtSiteID.Rows.Count; i++)
                {
                    if (i == dtSiteID.Rows.Count - 1)
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "'";
                    }
                    else
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "',";
                    }
                }
                if (strSiteID != "")
                {
                    strSQL = "Select * From Web_SiteTariff where SiteID in(" + strSiteID + ")";
                    return new CommonFun().GenDataTable(strSQL);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_SiteTariff", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //躉購設定          相關Table：Web_SiteSaleTariff
        #region public bool AddWeb_SiteSaleTariff     //新增案場躉購費率
        public bool AddWeb_SiteSaleTariff(string SiteID, DateTime StartDate, float Tariff, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");

                strSQL = " Insert Into Web_SiteSaleTariff(SiteID, StartDate, SaleTariff, ModifyUserID) ";

                strSQL += "  Values('" + SiteID + "','" + strStartDate + "'," + Tariff + ",'" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddWeb_SiteSaleTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool　UpdateWeb_SiteSaleTariff    //更新案場躉購費率
        public bool UpdateWeb_SiteSaleTariff(string SiteID, DateTime StartDate, float Tariff, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                strSQL = " Update Web_SiteSaleTariff Set  SaleTariff =" + Tariff + ", ModifyUserID='" + ModifyUserID + "', UpdateTime= GetDate() Where SiteID ='" + SiteID + "' and StartDate='" + strStartDate + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateWeb_SiteSaleTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool　DeleteWeb_SiteSaleTariff    //刪除案場躉購費率
        public bool DeleteWeb_SiteSaleTariff(string SiteID, DateTime StartDate)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                strSQL = " Delete From Web_SiteSaleTariff Where SiteID = '" + SiteID + "' and StartDate = '" + strStartDate + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DeleteWeb_SiteSaleTariff", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QueryWeb_SiteSaleTariff    //查詢案場躉購費率
        public DataTable QueryWeb_SiteSaleTariff()
        {
            try
            {
                strSQL = "Select * From Web_SiteSaleTariff";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_SiteSaleTariff", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryWeb_SiteSaleTariff    //查詢案場躉購費率
        public DataTable QueryWeb_SiteSaleTariff(DataTable dtSiteID)
        {
            try
            {
                string strSiteID = "";
                for (int i = 0; i < dtSiteID.Rows.Count; i++)
                {
                    if (i == dtSiteID.Rows.Count - 1)
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "'";
                    }
                    else
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "',";
                    }
                }
                if (strSiteID != "")
                {
                    strSQL = "Select * From Web_SiteSaleTariff where SiteID in(" + strSiteID + ")";
                    return new CommonFun().GenDataTable(strSQL);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_SiteSaleTariff", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


        //簡訊設定          相關Table：SnsConfig_cfg
        #region public bool AddSiteSNSConfig        //新增案場簡訊設定
        /// <summary>
        /// 新增案場簡訊設定
        /// </summary>
        /// <param name="SiteID">案場代碼</param>
        /// <param name="SnsIP">簡訊伺服器IP</param>
        /// <param name="SnsPort">簡訊伺服器Port</param>
        /// <param name="UserID">簡訊帳號</param>
        /// <param name="Password">簡訊密碼</param>
        /// <param name="bytUse">是否啟用（1：是，0：否）</param>
        /// <param name="ModifyUserID">修改者ID</param>
        /// <returns>回傳是否設定成功</returns>
        public bool AddSiteSNSConfig(string SiteID, string SnsIP, string SnsPort, string UserID, string Password, string bytUse, string ModifyUserID)
        {
            try
            {
                strSQL = " Insert Into SnsConfig_cfg(SiteID, SnsIP, SnsPort, UserID, Password, bytUse, ModifyUserID) ";
                strSQL += "  Values('" + SiteID + "','" + SnsIP + "'," + SnsPort + ",'" + UserID + "','" + Password + "','" + bytUse + "','" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddSiteSNSConfig", ex.ToString(), strSQL);
                return false;
            }        
        }
        #endregion

        #region public bool UpdateSiteSNSConfig     //修改案場簡訊設定
        /// <summary>
        /// 修改案場簡訊設定
        /// </summary>
        /// <param name="SiteID">案場代碼</param>
        /// <param name="SnsIP">簡訊伺服器IP</param>
        /// <param name="SnsPort">簡訊伺服器Port</param>
        /// <param name="UserID">簡訊帳號</param>
        /// <param name="Password">簡訊密碼</param>
        /// <param name="bytUse">是否啟用（1：是，0：否）</param>
        /// <param name="ModifyUserID">修改者ID</param>
        /// <returns>回傳是否更新設定成功</returns>
        public bool UpdateSiteSNSConfig(string SiteID, string SnsIP, string SnsPort, string UserID, string Password, string bytUse, string ModifyUserID)
        {
            try
            {
                strSQL = " Update SnsConfig_cfg Set SnsIP ='" + SnsIP + "', SnsPort ='" + SnsPort + "', UserID='" + UserID + "', Password='" + Password + "', bytUse='" + bytUse + "', ModifyUserID='" + ModifyUserID + "', UpdateTime = GetDate() ";
                strSQL += " Where SiteID ='" + SiteID + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateSiteSNSConfig", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelSiteSNSConfig
        /// <summary>
        /// 刪除案場簡訊設定
        /// </summary>
        /// <param name="SiteID">案場代碼</param>
        /// <returns>回傳是否刪除設定成功</returns>
        public bool DelSiteSNSConfig(string SiteID)
        {
            try
            {
                strSQL = " Delete From SnsConfig_cfg Where SiteID = '" + SiteID + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelSiteSNSConfig", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QuerySiteSNSConfig
        /// <summary>
        /// 查詢案場簡訊設定
        /// </summary>
        /// <returns>回傳相關資料DataTable</returns>
        public DataTable QuerySiteSNSConfig()
        {
            try
            {
                strSQL = " Select Case bytUse When '1' Then '是' Else '否' End as ShowUse, Web_Site.SiteName, SnsConfig_cfg.* From SnsConfig_cfg ";
                strSQL += " Join Web_Site On SnsConfig_cfg.SiteID = Web_Site.SiteID ";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteSNSConfig", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        //派工設備對應        相關Table：TagConfig_cfg、Web_OSSEquipment、GroupConfig_cfg
        #region public DataTable QueryTagbyGrpNo        //根據設備GrpNo查詢其監控點
        /// <summary>
        /// 根據設備GrpNo查詢其監控點（需為GroupConfig_cfg中最底層 bytIsDownLevel='0'）
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="GrpNo">群組編號</param>
        /// <returns>回傳監控點資料</returns>
        public DataTable QueryTagbyGrpNo(string SiteID, string GrpNo)
        {
            try
            {
                strSQL = "Select Case When Len(TagConfig_cfg.EquipID)>0 then Web_Site.SiteName+' / '+GroupConfig_cfg.GrpName+' / '+ TagName + ' / ' + Web_OSSEquipment.Location Else Web_Site.SiteName+' / '+GroupConfig_cfg.GrpName+' / '+ TagName + ' / ' End as ShowTagName, * From TagConfig_cfg ";
                strSQL += " Join GroupConfig_cfg On TagConfig_cfg.GrpNo = GroupConfig_cfg.GrpNo ";
                strSQL += " Join Web_Site On TagConfig_cfg.SiteID = Web_Site.SiteID  ";
                strSQL += " Left Join Web_OSSEquipment On TagConfig_cfg.EquipID = Web_OSSEquipment.EquipID ";
                strSQL += " Where TagConfig_cfg.SiteID ='" + SiteID + "' and TagConfig_cfg.GrpNo ='" + GrpNo + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryTagbyGrpNo", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryOSSCategory(string SiteID)     //查詢案場設備種類
        /// <summary>
        /// 查詢案場設備種類
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <returns>回傳設備種類</returns>
        public DataTable QueryOSSCategory(string SiteID)
        {
            try
            {
                strSQL = "Select Distinct Category From Web_OSSEquipment";
                strSQL += " Where SiteID ='" + SiteID + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryOSSCategory", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryOSSEquip(string SiteID, string Category)      //查詢OSS設備清單
        /// <summary>
        /// 查詢OSS設備清單
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="Category">設備種類</param>
        /// <returns>回傳OSS設備清單</returns>
        public DataTable QueryOSSEquip(string SiteID, string Category)
        {
            try
            {
                strSQL = "Select Category + ' / ' + EquipName + ' / ' + Location as ShowEquipName, * From Web_OSSEquipment";
                strSQL += " Where SiteID ='" + SiteID + "' and Category ='" + Category + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryOSSEquip", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public bool SetTagEquipID        //更新監控點設備ID
        /// <summary>
        /// 更新監控點設備ID
        /// </summary>
        /// <param name="SiteID">案場ID（PK）</param>
        /// <param name="MPLCNo">PLC編號（PK）</param>
        /// <param name="DevNo">設備編號（PK）</param>
        /// <param name="TagNo">監控點編號（PK）</param>
        /// <param name="GrpNo">群組編號（PK）</param>
        /// <param name="ObjNo">物件編號（PK）</param>
        /// <param name="EquipID">設備ID</param>
        /// <returns>回傳更新成功與否</returns>
        public bool SetTagEquipID(string SiteID, string MPLCNo, string DevNo, string TagNo, string GrpNo, string ObjNo, string EquipID)
        {
            try
            {
                strSQL = "Update TagConfig_cfg Set EquipID = '" + EquipID + "' ";
                strSQL += " Where SiteID ='" + SiteID + "' and MPLCNo ='" + MPLCNo + "' and DevNo ='" + DevNo + "' and TagNo ='" + TagNo + "' and GrpNo ='" + GrpNo + "' and ObjNo ='" + ObjNo + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("SetTagEquipID", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion



        //報表寄送設定        相關Table：Web_SiteReportMail
        #region public bool AddSiteReportMail        //新增案場簡訊設定
        /// <summary>
        /// 新增案場報表寄送設定，回傳設定成功或失敗
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="SendName">寄件者名稱</param>
        /// <param name="SendMailAddress">寄件者MailAddress</param>
        /// <param name="ReciveName">收件者名稱</param>
        /// <param name="ReciveMailAddress">收件者Mail Address（多筆可用『;』隔開）</param>
        /// <param name="Message">寄送訊息</param>
        /// <param name="ModifyUserID">修改人員ID</param>
        /// <returns>回傳設定成功或失敗</returns>
        public bool AddSiteReportMail(string SiteID, string SendName, string SendMailAddress, string ReciveName, string ReciveMailAddress, string Message, string ModifyUserID)
        {
            try
            {
                strSQL = " Insert Into Web_SiteReportMail(SiteID, SendName, SendMailAddress, ReciveName, ReciveMailAddress, Message, ModifyUserID) ";
                strSQL += "  Values('" + SiteID + "','" + SendName + "','" + SendMailAddress + "','" + ReciveName + "','" + ReciveMailAddress + "','" + Message + "','" + ModifyUserID + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddSiteReportMail", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool UpdateSiteReportMail     //修改案場簡訊設定
        /// <summary>
        /// 修改案場報表寄送設定，回傳設定成功或失敗
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="SendName">寄件者名稱</param>
        /// <param name="SendMailAddress">寄件者MailAddress</param>
        /// <param name="ReciveName">收件者名稱</param>
        /// <param name="ReciveMailAddress">收件者Mail Address（多筆可用『;』隔開）</param>
        /// <param name="Message">寄送訊息</param>
        /// <param name="ModifyUserID">修改人員ID</param>
        /// <returns>回傳設定成功或失敗</returns>
        public bool UpdateSiteReportMail(string SiteID, string SendName, string SendMailAddress, string ReciveName, string ReciveMailAddress, string Message, string ModifyUserID)
        {
            try
            {
                strSQL = " Update Web_SiteReportMail Set SendName ='" + SendName + "', SendMailAddress ='" + SendMailAddress + "', ReciveName='" + ReciveName + "', ReciveMailAddress='" + ReciveMailAddress + "', Message='" + Message + "', ModifyUserID='" + ModifyUserID + "', UpdateTime = GetDate() ";
                strSQL += " Where SiteID ='" + SiteID + "'";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateSiteReportMail", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelSiteReportMail
        /// <summary>
        /// 刪除案場報表寄送設定，回傳設定成功或失敗
        /// </summary>
        /// <param name="SiteID">案場代碼</param>
        /// <returns>回傳是否刪除設定成功</returns>
        public bool DelSiteReportMail(string SiteID)
        {
            try
            {
                strSQL = " Delete From Web_SiteReportMail Where SiteID = '" + SiteID + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelSiteReportMail-1", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable QuerySiteReportMail-1
        /// <summary>
        /// 查詢案場報表寄送設定
        /// </summary>
        /// <returns>回傳相關資料DataTable</returns>
        public DataTable QuerySiteReportMail()
        {
            try
            {
                strSQL = " Select Web_Site.SiteName, Web_SiteReportMail.* From Web_SiteReportMail ";
                strSQL += " Join Web_Site On Web_SiteReportMail.SiteID = Web_Site.SiteID ";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteReportMail", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QuerySiteReportMail-2
        /// <summary>
        /// 查詢案場報表寄送設定(根據單一案場別)
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <returns>回傳相關資料DataTable</returns>
        public DataTable QuerySiteReportMail(string SiteID)
        {
            try
            {
                strSQL = " Select Web_Site.SiteName, Web_SiteReportMail.* From Web_SiteReportMail ";
                strSQL += " Join Web_Site On Web_SiteReportMail.SiteID = Web_Site.SiteID ";
                strSQL += " Where Web_SiteReportMail.SiteID ='" + SiteID + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteReportMail-2", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QuerySiteReportMail-3
        /// <summary>
        /// 查詢案場報表寄送設定(根據使用者權限)
        /// </summary>
        /// <param name="SiteID">使用者ID</param>
        /// <param name="SiteID">使用者權限（預設為1）</param>
        /// <returns>回傳相關資料DataTable</returns>
        public DataTable QuerySiteReportMail(string UserID, string Role)
        {
            try
            {
                strSQL = " Select Web_Site.SiteName, Web_SiteReportMail.* From Web_SiteReportMail ";
                strSQL += " Join Web_Site On Web_SiteReportMail.SiteID = Web_Site.SiteID Join Web_UserRight on Web_SiteReportMail.SiteID = Web_UserRight.SiteID";
                strSQL += " Where Web_UserRight.UserID ='" + UserID + "' and Web_UserRight.Role = '" + Role + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QuerySiteReportMail-2", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        //查詢Web_KeyDefinitionConfig 相關Table：Web_KeyDefinitionConfig
        #region public DataTable QueryWeb_KeyDefinitionConfig()     //查詢Web_KeyDefinitionConfig
        /// <summary>
        /// 查詢Web_KeyDefinitionConfig
        /// </summary>
        /// <returns>回傳相關資料</returns>
        public DataTable QueryWeb_KeyDefinitionConfig()
        {
            try
            {
                strSQL = "Select * From Web_KeyDefinitionConfig";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_KeyDefinitionConfig", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        //查詢QueryGroupConfig_cfg 相關Table：GroupConfig_cfg
        #region public DataTable QueryGroupConfig_cfg(string GrpNo) //查詢GroupConfig_cfg
        /// <summary>
        /// 查詢GroupConfig_cfg
        /// </summary>
        /// <param name="GrpNo">GrpNo</param>
        /// <returns>回傳相關資料</returns>
        public DataTable QueryGroupConfig_cfg(string GrpNo)
        {
            try
            {
                strSQL = "Select * From GroupConfig_cfg where GrpNo='"+GrpNo+"'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryGroupConfig_cfg", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        //查詢QuerySiteAnnounce 相關Table：Web_SiteAnnounce
        #region public DataTable QueryAnnouncement(string SiteID, DateTime Query) //查詢Web_SiteAnnounce
        /// <summary>
        /// 查詢Web_SiteAnnounce
        /// </summary>
        /// <param name="SiteID">SiteID</param>
        /// <param name="Query">查詢的時間</param>
        /// <returns>回傳相關資料</returns>
        public DataTable QueryAnnouncement(string SiteID, DateTime Query)
        {
            try
            {
                strSQL = "Select * From Web_Announcement where SiteID='" + SiteID + "' and (StartDate<='" + Query.ToString("yyyy-MM-dd 00:00:00") + "' and  EndDate>='" + Query.ToString("yyyy-MM-dd 00:00:00") + "' or EndDate is null or EndDate ='')";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_Announcement", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        /// <summary>
        /// 查詢Web_SiteAnnounce
        /// </summary>
        /// <param name="dtSiteID">查詢的案場DataTable</param>
        /// <returns>回傳相關資料</returns>
        #region public DataTable QueryAnnouncement    //查詢案場公告
        public DataTable QueryAnnouncement(DataTable dtSiteID)
        {
            try
            {
                string strSiteID = "";
                for (int i = 0; i < dtSiteID.Rows.Count; i++)
                {
                    if (i == dtSiteID.Rows.Count - 1)
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "'";
                    }
                    else
                    {
                        strSiteID += "'" + dtSiteID.Rows[i]["SiteID"].ToString() + "',";
                    }
                }
                if (strSiteID != "")
                {
                    strSQL = "Select *, Case LV When '1' Then '重要' When '0' Then '一般' End as LVName From Web_Announcement where SiteID in(" + strSiteID + ")";
                    return new CommonFun().GenDataTable(strSQL);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_Announcement", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion
        //查詢案場地圖資料 相關Table：Web_SiteMap
        #region public DataTable QuerySiteMap(string strSiteID)
        /// <summary>
        /// 傳入SiteID查詢案場圖控頁面資料
        /// </summary>
        /// <param name="strSiteID">案場ID</param>
        /// <returns>查詢案場地圖資料</returns>
        public DataTable QuerySiteMap(string strSiteID)
        {
            try
            {
                strSQL = "Select * From Web_SiteMap where SiteID='" + strSiteID + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryWeb_SiteMap", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion


    }
}
